import { message } from 'antd';
import axios from 'axios';
import NproGress from 'nprogress';
import 'nprogress/nprogress.css';
const instance = axios.create({
  baseURL: 'http://fangadmin.shbwyz.com',
});

const whiteList = [
  {
    method: 'get',
    url: '/getChatlist',
  },
  {
    method: 'get',
    url: '/getTourlist',
  },
  {
    method: 'get',
    url: '/getServelist',
  },
];

// 添加请求拦截器
axios.interceptors.request.use((config) => {
  NproGress.start();
  return config;
});

// 添加响应拦截器
axios.interceptors.response.use((config: any) => {
  // console.log(config);
  const flag = whiteList.some(
    (item) =>
      item.method === config.config.method &&
      item.url.includes(config.config.url),
  );
  // console.log(flag);
  if (flag) {
    message.success('请求成功');
  }
  NproGress.done();

  return config;
});

// 添加请求拦截器
instance.interceptors.request.use((config) => {
  // NproGress.start();
  return config;
});

// 添加响应拦截器
instance.interceptors.response.use((config) => {
  // NproGress.done();
  return config;
});

export { instance, axios };
